﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LogicExpressionCalculator;

namespace FeatureModelCore.FMAnalyzer
{
    public class ExpressionGenerator
    {
        /// <summary>
        /// Two Operand
        /// </summary>
        /// <param name="oper"></param>
        /// <param name="operand1"></param>
        /// <param name="operand2"></param>
        /// <returns></returns>
        public static AbstractExpressionObject[] GeneratorTwoOperandExpression(
            LogicOperator oper, AbstractExpressionObject[] operand1,
            AbstractExpressionObject[] operand2)
        {
            List<AbstractExpressionObject> newExpr = new List<AbstractExpressionObject>();
            newExpr.Add(oper);
            newExpr.AddRange(operand1);
            newExpr.AddRange(operand2);
            return newExpr.ToArray<AbstractExpressionObject>();
        }
        /// <summary>
        /// Not Operand. Negative
        /// </summary>
        /// <param name="oper"></param>
        /// <param name="operand1"></param>
        /// <param name="operand2"></param>
        /// <returns></returns>
        public static AbstractExpressionObject[] GeneratorOneOperandExpression(
    AbstractExpressionObject[] operand)
        {
            List<AbstractExpressionObject> newExpr = new List<AbstractExpressionObject>();
            newExpr.Add(LogicOperator.Negation);
            newExpr.AddRange(operand);
            return newExpr.ToArray<AbstractExpressionObject>();
        }
        /// <summary>
        /// And, Or Group
        /// </summary>
        /// <param name="operands">and , or</param>
        /// <returns></returns>
        public static AbstractExpressionObject[] Group(LogicOperator oper,
            AbstractExpressionObject[][] operands)
        {
            List<AbstractExpressionObject> newExpr = new List<AbstractExpressionObject>();
            int count = operands.Length - 1;
            for (int i = 0; i < count; ++i)
            {
                newExpr.Add(oper);
            }
            foreach (AbstractExpressionObject[] objs in operands)
            {
                newExpr.AddRange(objs);
            }
            return newExpr.ToArray<AbstractExpressionObject>();
        }
    }
}
